package com.LostAndFound.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import com.LostAndFound.domain.Root;
import com.LostAndFound.domain.User;
import com.LostAndFound.utils.DataSourceUtils;

public class LoginDao {

	public Root findRootForLogin(String username, String password) throws SQLException {
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "select * from root where username=? and password=?";
		Root root = runner.query(sql, new BeanHandler<Root>(Root.class),username,password);
		return root;
	}

	public User findUserForLogin(String username, String password) throws SQLException {
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "select * from user where username=? and password=?";
		User user = runner.query(sql, new BeanHandler<User>(User.class),username,password);
		return user;
	}

}
